<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title></title>
<%@ include file="/WEB-INF/views/include/easyui.jsp"%>
<script src="${ctx}/static/plugins/My97DatePicker/WdatePicker.js" type="text/javascript"></script>

</head>
<body style="font-family: '微软雅黑'">
<div id="tb" style="padding:5px;height:auto">
        <div>
        	<form id="searchFrom" action="">
       	        <input type="text" name="filter_LIKES_pname" class="easyui-validatebox" data-options="width:220,prompt: '产品名称'"/>
       	        <input type="text" name="filter_LIKES_pcode" class="easyui-validatebox" data-options="width:150,prompt: '产品编码'"/>
		        <span class="toolbar-item dialog-tool-separator"></span>
		        <a href="javascript(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="cx()">查询</a>
			</form>
			<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-hamburg-library" plain="true" onclick="detail();">查看</a>
	       	<span class="toolbar-item dialog-tool-separator"></span>
	       	
	       	<shiro:hasPermission name="lcs:product:add">
	       		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add();">添加</a>
	       		<span class="toolbar-item dialog-tool-separator"></span>
	       	</shiro:hasPermission>
	       	<shiro:hasPermission name="lcs:product:delete">
	            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" data-options="disabled:false" onclick="del()">删除</a>
	        	<span class="toolbar-item dialog-tool-separator"></span>
	        </shiro:hasPermission>
	        <shiro:hasPermission name="lcs:product:update">
	            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="upd()">修改</a>
	            <span class="toolbar-item dialog-tool-separator"></span>
	        </shiro:hasPermission>
	        
	        <shiro:hasPermission name="lcs:product:upload">
	            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-hamburg-up" plain="true" onclick="uploadImg()">图片</a>
	            <span class="toolbar-item dialog-tool-separator"></span>
	        </shiro:hasPermission>
	        
	        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-hamburg-credit-card" plain="true" onclick="viewDetailUrl();">预览详情页</a>
	       	<span class="toolbar-item dialog-tool-separator"></span>
	       	
	       	<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-hamburg-credit-card" plain="true" onclick="viewShareUrl();">预览分享页</a>
	        
	       	<shiro:hasPermission name="lcs:product:publish">
	       		<span class="toolbar-item dialog-tool-separator"></span>
	            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-hamburg-product" plain="true" onclick="publish()">发布</a>
	        </shiro:hasPermission>
	        
        </div> 
        
</div>
<table id="dg"></table> 
<div id="dlg"></div>  
<script type="text/javascript">
var dg;
$(function(){   
	dg=$('#dg').datagrid({    
	method: "get",
    url:'${ctx}/product/json',
    queryParams:{
    		sort: 'recordTime', 
    		order: 'desc'
    		},
    fit : true,
	fitColumns : true,
	border : false,
	striped:true,
	idField : 'id',
	pagination:true,
	rownumbers:true,
	pageNumber:1,
	pageSize : 20,
	pageList : [ 10, 20, 30, 40, 50 ],
	singleSelect:true,
    columns:[[    
		{field:'id',title:'id',hidden:true},  
		{field:'imgUrl',title:'产品图片',width:60,align:'center',formatter:function(value,rowData,rowIndex){
			return '<img width="75" height="60" src="'+rowData.imgUrl+'" />';
		}},
		{field:'pname',title:'产品名称',sortable:false,width:100},
		{field:'pcode',title:'产品编码',align:'center',sortable:false,width:40},
        {field:'ptcode',title:'产品类型',align:'center',sortable:false,width:40,formatter:function(value,rowData,rowIndex){
			return value != null ? value.typename : '';
		}},   
        {field:'totalMoney',title:'产品总额',width:50,align:'center',sortable:false,formatter:function(value,rowData,rowIndex){
			return formatMoney(value);
		}},
        {field:'fullStatus',title:'是否售罄',width:40,align:'center',sortable:false,formatter:function(value,rowData,rowIndex){
			if(value == '1') {
				return "<span style='color: red;'>已售罄</span>";
			} else {
				return "<span style='color: green;'>在售中</span>";
			}
		}},
        {field:'hotStatus',title:'产品状态',width:40,align:'center',sortable:false,formatter:function(value,rowData,rowIndex){
			if(value == '3') {
				return "<span style='color: red;'>轮播</span>";
			} else if(value == '2') {
				return "<span style='color: green;'>热门</span>";
			} else if(value == '1') {
				return "<span style='color: green;'>推荐</span>";
			} else {
				return "<span>普通</span>";
			}
		}},
		{field:'beginAgentDay',title:'开始日期',width:50,align:'center',sortable:false},
		{field:'endPaymentDay',title:'结束日期',width:50,align:'center',sortable:false},
		{field:'publishStatus',title:'发布状态',width:40,align:'center',sortable:false,formatter:function(value,rowData,rowIndex){
			if(value == '0') {
				return "<span style='color: red;'>未发布</span>";
			} else {
				return "<span style='color: green;'>已发布</span>";
			}
		}},
		{field:'recordTime',title:'发布时间',width:68,align:'center',sortable:false,formatter:function(value,rowData,rowIndex){
			return formatTime(value);
		}}
    ]],
    enableHeaderClickMenu: false,
    enableHeaderContextMenu: false,
    enableRowContextMenu: false,
    toolbar:'#tb'
	});
});

//弹窗查看
function detail(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	d=$("#dlg").dialog({   
	    title: '查看产品',    
	    width: 640,    
	    height: 300,   
	    href:'${ctx}/product/update/'+row.id,
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'取消',
			handler:function(){
					d.panel('close');
				}
		}]
	});
}

//弹窗增加
function add() {
	d=$("#dlg").dialog({   
	    title: '添加产品',    
	    width: 640,    
	    height: 300,    
	    href:'${ctx}/product/create',
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'确认',
			handler:function(){
				$("#mainform").submit(); 
				dg.datagrid('reload');
			}
		},{
			text:'取消',
			handler:function(){
					d.panel('close');
				}
		}]
	});
}

//删除
function del(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	parent.$.messager.confirm('提示', '删除后无法恢复您确定要删除？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"${ctx}/product/delete/"+row.id,
				success: function(data){
					successTip(data,dg);
				}
			});
		} 
	});
}

//弹窗修改
function upd(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	d=$("#dlg").dialog({   
	    title: '修改产品',    
	    width: 640,    
	    height: 300,   
	    href:'${ctx}/product/update/'+row.id,
	    maximizable:true,
	    modal:true,
	    buttons:[{
			text:'修改',
			handler:function(){
				$('#mainform').submit(); 
			}
		},{
			text:'取消',
			handler:function(){
					d.panel('close');
				}
		}]
	});
}

//图片上传
function uploadImg() {
	var row = dg.datagrid('getSelected');
	if (rowIsNull(row))
		return;
	d = $("#dlg").dialog({
		title : '图片上传',
		width : 450,
		height : 300,
		href : '${ctx}/product/upload/' + row.id,
		maximizable : true,
		modal : true,
		buttons : [ {
			text : '确认',
			handler : function() {
				$("#uploadform").submit();
				setTimeout("dg.datagrid('reload')", 1500);
			}
		}, {
			text : '取消',
			handler : function() {
				d.panel('close');
			}
		} ]
	});

}

//产品详情页预览
function viewDetailUrl(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	
	if(!row.detailUrl || row.detailUrl=='') {
		parent.$.messager.alert('该产品没有详情页！');
		return;
	}
	
	var url = row.detailUrl + "?pcode=" + row.pcode;
	window.open(url,"","width=320,height=680,toolbar=no,scrollbars=yes,menubar=no,screenX=100,screenY=100");
}

//产品分享页预览
function viewShareUrl(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	
	if(!row.shareUrl || row.shareUrl=='') {
		parent.$.messager.alert('该产品没有分享页！');
		return;
	}
	
	var url = row.shareUrl + "?pcode=" + row.pcode;
	window.open(url,"","width=320,height=680,toolbar=no,scrollbars=yes,menubar=no,screenX=100,screenY=100");
}

//产品发布
function publish(){
	var row = dg.datagrid('getSelected');
	if(rowIsNull(row)) return;
	if(row.publishStatus == '1') {
		parent.$.messager.alert('该产品已发布！');
		return;
	}
	parent.$.messager.confirm('提示', '确认要发布该产品么？', function(data){
		if (data){
			$.ajax({
				type:'get',
				url:"${ctx}/product/publish/"+row.id,
				success: function(data){
					successTip(data,dg);
				}
			});
		} 
	});
}

//创建查询对象并查询
function cx(){
	var obj=$("#searchFrom").serializeObject();
	obj.filter_LIKES_pname = encodeURIComponent(obj.filter_LIKES_pname);
	dg.datagrid('reload',obj); 
}

</script>
</body>
</html>